package wms.camera.project;

import java.io.File;

import android.app.Activity;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.Toast;

public class PictureDisplayActivity extends Activity implements OnClickListener{

	private ImageView image;
	private EditText status;
	private Button startOver, sendPicture;
	private File pictureFile;
	
	/** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.picture);
        
        //Setup GUI objects
        image = (ImageView) findViewById(R.id.image);
        status = (EditText) findViewById(R.id.status);
        startOver = (Button) findViewById(R.id.startOver);
        startOver.setOnClickListener(this);
        sendPicture = (Button) findViewById(R.id.sendPicture);
        sendPicture.setOnClickListener(this);
        
        //Get picture and display it
        pictureFile = new File("/sdcard/images/pic.jpg");
        String fileStatus = "File not found!";
		if (pictureFile != null && pictureFile.exists()) {
			Bitmap myBitmap = BitmapFactory.decodeFile(pictureFile.getAbsolutePath());
		    image.setImageBitmap(myBitmap);
		    
		    fileStatus = "File was found!";
		}
        
		status.setText(fileStatus);
    }
	
	public void onClick(View v) {
		if (v.getId() == R.id.startOver) {
			Intent cameraIntent = new Intent(v.getContext(), AndroidCameraProjectActivity.class);
			startActivityForResult(cameraIntent, 0);
		}
		else if (v.getId() == R.id.sendPicture) {
			Intent mailIntent = new Intent(Intent.ACTION_SEND);
			mailIntent.setType("message/rfc822");
			mailIntent.putExtra(Intent.EXTRA_EMAIL, "pacom20003@hotmail.com");
			mailIntent.putExtra(Intent.EXTRA_SUBJECT, "Android Picture App");
			mailIntent.putExtra(Intent.EXTRA_TEXT, "This message was sent from Android");
			
			try {
			    startActivity(Intent.createChooser(mailIntent, "Send mail..."));
			} catch (android.content.ActivityNotFoundException ex) {
			    Toast.makeText(this, "There are no email clients installed.", Toast.LENGTH_SHORT).show();
			}
		}
	}

}
